//https://leetcode.cn/problems/valid-anagram/
package codeRandomThoughts.Test242有效的字母异位词;

//二刷
public class Solution2 {

    public boolean isAnagram(String s, String t) {
        //每个字符出现的次数都相同
        int[] alphabet = new int[26];

        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            alphabet[c-'a']++;
        }

        for (int i = 0; i < t.length(); i++) {
            char c = t.charAt(i);
            alphabet[c-'a']--;
        }

        for (int j : alphabet) {
            if (j != 0) {
                return false;
            }
        }
        return true;
    }
}
